If you are debugging IPTables, it is handy to be able to trace the packets while it traverses the various chains. I was trying to find out why port forwarding from the external NIC to a virtual machine attached to a virtual bridge device was not working.
You need to perform the following preparations:
- Load the (IPv4) netfilter log kernel module:
# modprobe nf_log_ipv4
- Enable logging for the IPv4 (AF Family 2):
# sysctl net.netfilter.nf_log.2=nf_log_ipv4
- reconfigure rsyslogd to log kernel messages (kern.*) to /var/log/messages:
1 | # cat /etc/rsyslog.conf | grep -e "^kern" |
- restart rsyslogd:
# systemctl restart rsyslog
Now check the raw tables – you’ll see that there are already entries coming from firewalld:
1 | # iptables -t raw -L |
We’ll want to add our tracing rules before the existing rules. In this example we’ll trace everything related to HTTP (port 80)
1 | # iptables -t raw -j TRACE -p tcp --dport 80 -I PREROUTING 1 |
The rules now look as follows:
1 | # iptables -t raw -L |
See also:
http://backreference.org/2010/06/11/iptables-debugging/
https://home.regit.org/2014/02/nftables-and-netfilter-logging-framework/
原文:http://www.opensourcerers.org/how-to-trace-iptables-in-rhel7-centos7/